package cn.wen.java.sql.ds;

import java.util.List;
import java.util.Map;

/**
 * Title：数据仓库
 * <p>
 * Description：ResultSet的反转实体。
 * <p>
 * Copyright：Copyright (c) 2010-2012
 * 
 * @author <a href="mailto:ct_wen@qq.com">ctwen</a>, 温承瑭
 * @version Revision：1.0 Date：2011/5/22 Description：初完成。
 *          <p>
 *          Revision：1.1 Date：2011/9/8 Description：添加列信息描述（成员）。
 *          <p>
 */
public class Datastore implements IDatastore {

    // ---------------------------------------------------------------------
    //
    // ---------------------------------------------------------------------

    public Datastore(List<Map<String, DataCell>> dslm, List<List<DataCell>> dsll) {
	super();
	this.dslm = dslm;
	this.dsll = dsll;
    }

    public Datastore() {
	super();
    }

    // ---------------------------------------------------------------------
    //
    // ---------------------------------------------------------------------

    private int rowCount = 0;

    protected InfoColumn[] infoColumns;

    protected List<Map<String, DataCell>> dslm;

    protected List<List<DataCell>> dsll;

    public InfoColumn[] getInfoColumns() {
	return infoColumns;
    }

    public void setInfoColumns(InfoColumn[] infoColumns) {
	this.infoColumns = infoColumns;
    }

    public List<Map<String, DataCell>> getDslm() {
	return dslm;
    }

    public void setDslm(List<Map<String, DataCell>> dslm) {
	this.dslm = dslm;
    }

    public List<List<DataCell>> getDsll() {
	return dsll;
    }

    public void setDsll(List<List<DataCell>> dsll) {
	this.dsll = dsll;
    }

    // ---------------------------------------------------------------------
    //
    // ---------------------------------------------------------------------

    @Override
    public DataCell get(int rowIndex, int colIndex) {
	return this.dsll.get(rowIndex).get(colIndex);
    }

    @Override
    public DataCell get(int rowIndex, String colKey) {
	return this.dslm.get(rowIndex).get(colKey);
    }

    @Override
    public List<DataCell> getRowAsList(int rowIndex) {
	return this.dsll.get(rowIndex);
    }

    @Override
    public Map<String, DataCell> getRowAsMap(int rowIndex) {
	return this.dslm.get(rowIndex);
    }

    @Override
    public int getRowCount() {
	return this.rowCount == 0 ? this.rowCount = this.dsll.size() : this.rowCount;
    }

    public void setRowCount(int rowCount) {
	this.rowCount = rowCount;
    }

    @Override
    public String toJSONString() {
	return DSHelper.toJson(this);
    }

    @Override
    public String toString() {
	return this.getDslm() + " - " + super.toString();
    }

}
